#ifndef APPDATAMODEL_H
#define APPDATAMODEL_H

#include <QAbstractListModel>

#include "dbmanager.h"

class AppDataModel : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(int type MEMBER m_modelType READ type WRITE setType NOTIFY typeChanged FINAL)
public:
    enum ModelType {
        FULL, // Full Application
        SPECIAL // Subpart Application
    };
    Q_ENUM(ModelType)
    enum AppDataRole
    {
        AppNameRole = Qt::DisplayRole,
        AppIconRole = Qt::UserRole,
    };
    Q_ENUM(AppDataRole)

    AppDataModel(QObject *parent = nullptr);
    virtual ~AppDataModel();

    int rowCount(const QModelIndex & = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;
    // CURD
    Q_INVOKABLE QVariantMap get(int row) const;
    Q_INVOKABLE void append(const QString &appName, const QString &appIcon);
    // Q_INVOKABLE void set(int row, const QString &fullName, const QString &address, const QString  &city, const QString &number);
    Q_INVOKABLE void remove(int row);

    // PROPERTY
    int type() const;
    void setType(const int type);
private:
    DBManager *m_dbManager;
    int m_modelType;
    struct Entity
    {
        QString appName;
        QString appIcon;
    };
    QList<Entity> m_appData;

signals:
    void typeChanged(const int type);
};

#endif // APPDATAMODEL_H
